'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE } = app.Sequelize;
  const User = app.model.define('user',
    {
      id: {
        type: INTEGER,
        primaryKey: true,
        autoIncrement: true,
      },
      username: STRING(255),
      password: STRING(255),
      enable: {
        type: INTEGER,
        defaultValue: 1,
      },
      create_time: DATE,
      update_time: DATE,
    },
    {
      freezeTableName: true, // Model 对应的表名将与model名相同
      timestamps: false,
    }
  );

  // 表关联
  // User.associate = function() {
  //   app.model.User.hasMany(app.model.Test2, { foreignKey: 'id', sourceKey: 'test_id' });// 一对多
  //   app.model.User.belongsTo(app.model.Test3, { foreignKey: 'id', targetKey: 'test_id' }); // 一对一
  // };

  return User;
};
